home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD-ROM Today - The Disc! 5
/
CD-ROM Today - The Disc (Issue 5)(November 1994).ISO
/
mac
/
Mac shareware
/
Education
/
RLaB
/
rlib
/
printmat.r
< prev
next >
Wrap
Text File
|
1994-09-21
|
3KB
|
124 lines
//--------------------------------------------------------------------------------
//
// printmat
//
// Syntax: printmat(a,anme,rlab,clab);
//
// This routine prints the matrix a using the title contained in the
// string name and the row labels contained in rowlab and the
// column labels contained in collab. Note: rowlab and collab are
// vectors of strings, such as
//
// rowlab[1]="alpha";
// rowlab[2]="beta";
// rowlab[3]="gamma";
//
// Note: name, rowlab, and collab are optional variables.
//
//--------------------------------------------------------------------------------
printmat = function(a,mname,rowlab,collab)
{
local(nrows,ncols,col_per_scrn,len,col,n,icol,nmax,...
i,j,k,sdum,element,ishift,narg, rl, cl, s, tmp)
narg=0;
if (!exist (a)) { error ("printmat: must supply a matrix"); }
if (!exist (mname)) { mname = ""; }
if (!exist (rowlab)) { rl = []; else rl = rowlab; }
if (!exist (collab)) { cl = []; else cl = collab; }
nrows=a.nr;
ncols=a.nc;
// Create row and column labels if necessary
if (rl.n == 0)
{
for (i in 1:nrows)
{
sprintf (tmp, "%3i", i);
rl[i]="--"+ tmp +" --> ";
}
}
if (cl.n == 0)
{
for (i in 1:ncols) { cl[i]="----"+int2str(i)+"---- "; }
}
col_per_scrn=5;
len=12;
if ((nrows==0)||(ncols==0)) {
if (length (mname)) {
printf(" \n%s = \n \n",mname);
return 0;
}
printf(" \n%s \n"," [] \n");
return 0;
}
// Print matrix name
col=1;
n = min([col_per_scrn-1,ncols-1]);
if (length (mname)) {
printf("\n%s = \n \n",mname);
}
// Print column labels
s="";
icol=0;
while (col <= ncols) {
icol=icol+1;
s=" ";
for (j in 0:n) {
ishift=12-length(cl[j+col]);
for (k in 1:ishift) {
s=s+" ";
}
s=s+cl[j+col];
}
printf("%s\n",s);
// Print Row Labels
for (i in 1:nrows) {
s=""+rl[i];
ishift=12-length(rl[i]);
for (k in 1:ishift) {
s=s+" ";
}
for (j in 0:n) {
element = a[i;col+j];
if (element == 0) {
s=s+" 0";
else if (element >= 1.0e+06) {
sdum="";
sprintf(sdum,"%12.5e",element);
s=s+sdum;
else if (element <= -1.0e+05) {
sdum="";
sprintf(sdum,"%12.5e",element);
s=s+sdum;
else if (abs(element) < 0.0001) {
sdum="";
sprintf(sdum,"%12.5e",element);
s=s+sdum;
else
sdum="";
sprintf(sdum,"%12.5f",element);
s=s+sdum;
}}}}
}
printf("%s\n",s);
}
col = col+col_per_scrn;
printf("%s"," \n");
if ((ncols-col) < n) {
n=ncols-col;
}
}
return 0;
};